package com.yunweiweishi.xuhuanpaltform.yuhuan_app.controller;


import com.yunweiweishi.xuhuanpaltform.yuhuan_app.comm.conf.CommonResult;
import com.yunweiweishi.xuhuanpaltform.yuhuan_app.pojo.EquipmentPart;
import com.yunweiweishi.xuhuanpaltform.yuhuan_app.service.EquipmentPartService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/EquipmentPart")
public class EquipmentPartController {



    @Autowired
    private CommonResult result;



    @Autowired
    private EquipmentPartService equipmentPartService;



    /**
     *
     */

    /**
     * 根据设备的部位的名称进行查询
     *
     * @param equipmentPartName
     * @return
     */
    @GetMapping("/findByEquipmentPartName")
    public CommonResult findByEquipmentPartName(@RequestParam("equipmentPartName") String equipmentPartName) {


        try {
            EquipmentPart equipmentPart = equipmentPartService.findByEquipmentPartName(equipmentPartName);
            result.setData(equipmentPart);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            result.setState(500);
            result.setMsg("失败");
            return result;
        }





    }





    @ApiOperation(value = "设备的部位的的添加")
    @PostMapping("/addEquipmentPart")
    public CommonResult addEquipmentPart(@RequestBody EquipmentPart equipmentPart) {

        try {

            equipmentPartService.addEquipmentPart(equipmentPart);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            result.setState(500);
            result.setMsg("失败");
            return result;
        }

    }
    @ApiOperation( value = "更新设备的部位")
    @PutMapping("/updateEquipmentPart")
    public CommonResult updateEquipmentPart(@RequestBody EquipmentPart equipmentPart) {

        try {

            equipmentPartService.updateEquipmentPart(equipmentPart);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            result.setState(500);
            result.setMsg("失败");
            return result;
        }

    }


    @ApiOperation( value = "根据id删除设备")
    @DeleteMapping("/deleteEquipmentType/{id}")
    public void deleteEquipmentPartById(@PathVariable("id") Long id) {

        equipmentPartService.deleteEquipmentPartById(id);

    }



}
